package com.xtrip.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class InitializationListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		
		ServletContext sc = event.getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
//		
//		// 加载平台配置文件
//		
		InputStream inStream1 = sc.getResourceAsStream(sc.getInitParameter("configLocation"));
		try {
			
			Properties p = new Properties();
			p.load(inStream1);
//			
			BusinessConstant.REQUEST_URL_ZHUNA = p.getProperty("url_zhuna");
			BusinessConstant.REQUEST_URL_CTRIP = p.getProperty("url_ctrip");
			BusinessConstant.REQUEST_URL_ELONG = p.getProperty("url_elong");
			BusinessConstant.REQUEST_URL_17U = p.getProperty("url_17u");
			BusinessConstant.AGENTID_ZHUNA = p.getProperty("agent_id_zhuna");
			BusinessConstant.AGENTMD_ZHUNA = p.getProperty("agent_md_zhuna");
			BusinessConstant.POSTMD_ZHUNA = p.getProperty("agent_postmd_zhuna");
			BusinessConstant.ALLIANCECOD_CTRIP = p.getProperty("alliance_cod_ctrip");
			BusinessConstant.SITEID_CTRIP = p.getProperty("site_id_ctrip");
			BusinessConstant.APIKEY_CTRIP = p.getProperty("apikey_ctrip");
//			
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (null != inStream1) {
					inStream1.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
